﻿using UnityEngine;
using System.Collections;

public class ItemMove : MonoBehaviour {
    public Vector3 targetPos;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, targetPos, 0.1f);
	}
    public static void moveToPos(GameObject targetObj, Vector3 pos)
    {
        ItemMove im = targetObj.GetComponent<ItemMove>();
        if (im != null) {
            Destroy(im);
        }
        targetObj.AddComponent<ItemMove>().targetPos = pos;
    }
    public static void moveToPos(GameObject targetObj, Vector3 pos, float destroyTime)
    {
        ItemMove im = targetObj.GetComponent<ItemMove>();
        if (im != null)
        {
            Destroy(im);
        }
        targetObj.AddComponent<ItemMove>().targetPos = pos;
        Destroy(targetObj, destroyTime);
    }
}
